home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / tex / tools / dvi / hp_90.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  5.3 KB  |  242 lines

  1. /*********************************************************************
  2. ****    Universaltreiber für HP-kompatible Drucker                ****
  3. *********************************************************************/
  4.  
  5. /* Siehe auch Datei JP350WS.C */
  6.  
  7. #include <portab.h>
  8. #include <atarierr.h>
  9.  
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. #include "mintbind.h"
  14. #include "treiber.h"
  15.  
  16.  
  17. /********************************************************************/
  18. /* Setzt die freien Werte auf Standartwerte */
  19.  
  20. #ifndef OBEN    /* Wenn noch kein oberer Rand definiert */
  21. #define OBEN 0L
  22. #endif
  23.  
  24. #ifndef LINKS    /* Wenn noch kein linker Rand definiert */
  25. #define LINKS 0L
  26. #endif
  27.  
  28. #ifndef MAX_DPI    /* Wenn keine maximale Auflösung definiert */
  29. #define MAX_DPI 1200L
  30. #endif
  31.  
  32. #ifndef BREITE    /* druckbare Breite (in Pixel) */
  33. #define BREITE ((2336L*MAX_DPI)/300L)
  34. #endif
  35.  
  36. #ifndef HOEHE        /* druckbare Höhe (in Pixel) */
  37. #define HOEHE ((3386L*MAX_DPI)/300L)
  38. #endif
  39.  
  40. #ifdef FAST_PRN
  41. #define WRITE(i,j) ((th>0)?(Fwrite(th,i,j)):(print_block(i,j)))
  42. #endif
  43.  
  44. /********************************************************************/
  45.  
  46.  
  47.  
  48. /* Findet entweder Wiederholung (TRUE) oder nichts */
  49. WORD    find_next_same( WORD *rep, UBYTE *p, LONG limit )
  50. {
  51.     WORD    i;
  52.  
  53.         /* Spezialfälle */
  54.     if(  limit<1  )
  55.     {
  56.         *rep = 1;
  57.         return FALSE;
  58.     }
  59.     if( limit<2  &&  p[0]==p[1]  )
  60.     {
  61.         *rep = 2;
  62.         return TRUE;
  63.     }
  64.  
  65.         /* Sonst getrennt */
  66.     if(  p[0]==p[1]  &&  p[1]==p[2]  )
  67.     {
  68.         /* Abstand zum nächsten Ungleichen... */
  69.         i = 3;
  70.         while(  i<128  &&  i<limit  &&  p[0]==p[i]  )
  71.             i++;
  72.         *rep = i;
  73.         return TRUE;
  74.     }
  75.     else
  76.     {
  77.         /* ... bzw. Gleichen ermitteln */
  78.         i = 0;
  79.         while(  i<128  &&  i<limit  &&  !(p[i]==p[i+1]  &&  p[i]==p[i+2])  )
  80.             i++;
  81.         *rep = i;
  82.         return FALSE;
  83.     }
  84. }
  85. /* 17.1.93 */
  86.  
  87.  
  88. static UBYTE    druckzeile[1024];
  89.  
  90.  
  91. WORD    drucke( UBYTE *p, LONG weite, LONG max_zeile, LONG h_dpi, LONG v_dpi )
  92. {
  93.     UBYTE    tmp1[50], tmp2[(BREITE+15)/7];
  94.     LONG    rechts, i, j, x, v_hoehe, v_weite;
  95.     WORD    th, rep, modus=0/* Komprimiert oder nicht? */;
  96.     extern char    tmp_file[256]; /* In Datei drucken? */
  97.  
  98. #ifdef FAST_PRN
  99.     /* Für viel Geschwindigkeit = sinnvoll großer Puffer */
  100.     if(  tmp_file[0]>0  ||  open_printer()<0  )
  101. #endif
  102.         th = (WORD)get_tempfile( "hpq" );
  103.     if(  th<0  )
  104.         return -1;
  105.  
  106.     if(  h_dpi>700  )
  107.         h_dpi = 1200;
  108.     else if(  h_dpi>350  )
  109.         h_dpi = 600;
  110.     else if(  h_dpi>175  )
  111.         h_dpi = 300;
  112.     else if(  h_dpi>110  )
  113.         h_dpi = 150;
  114.     else if(  h_dpi>80  )
  115.         h_dpi = 100;
  116.     else
  117.         h_dpi = 75;
  118.  
  119.         /* Unsinnige Werte werden als Maximum angenommen */
  120.     if(  h_dpi<=0  ||  h_dpi>MAX_DPI  )
  121.         h_dpi = MAX_DPI;
  122.  
  123.     i = (OBEN*h_dpi)/MAX_DPI;
  124.     p += ((weite+15)/16)*2*i;    /* Nicht druckbare Ränder*/
  125.  
  126.     v_weite = weite;
  127.     if(  v_weite>(HOEHE*h_dpi)/MAX_DPI  )
  128.         v_weite = (HOEHE*h_dpi)/MAX_DPI;
  129.     weite = ((weite+15)/16)*2;
  130.  
  131.     max_zeile = max_zeile-i-1;
  132.     v_hoehe = max_zeile;
  133.     if(  v_hoehe>(BREITE*h_dpi)/MAX_DPI  )
  134.         v_hoehe = (BREITE*h_dpi)/MAX_DPI;
  135.     max_zeile = v_hoehe;
  136.  
  137.         /* Ränder feststellen */
  138.     for(  x=0;  x*8<v_hoehe  &&  ist_next_leer( p+x, weite, max_zeile );  x++  )
  139.         ;
  140.  
  141.     x *= 8;
  142.     if(  x>=v_hoehe  )
  143.     {
  144.         /* Seite leer */
  145.         WRITE( 5L, " \33*rB\14" ); /*FF*/
  146.         flush_block();
  147.         return 0;
  148.     }
  149.  
  150.         /* In die obere Ecke */
  151.     WRITE( 26, " \33*p0Y\33*p-300Y\33*p0X\33*p-300X" );
  152.         /* Grafikdruck Anfang */
  153.     strcpy( tmp1, "\33&100L\33*rB\33*t" );
  154.         /* Grafikauflösung festlegen */
  155.     ltoa( h_dpi, tmp1+13, 10 );
  156.     strcat( tmp1, "R\33*r" );
  157.     WRITE( strlen(tmp1), tmp1 );
  158.         /* Grafikweite festlegen */
  159.     ltoa( v_hoehe, tmp1, 10 );
  160.     v_hoehe = (v_hoehe+7)/8+1;
  161.     strcat( tmp1, "s0A" );
  162.     WRITE( strlen(tmp1), tmp1 );
  163.  
  164.  
  165.     if(  x-LINKS>0  )
  166.     {
  167.         strcpy( tmp1, "\33*b" );
  168.         ltoa( x, tmp1+3, 10 );
  169.         strcat( tmp1, "Y" );
  170.         WRITE( strlen(tmp1), tmp1 );
  171.     }
  172.     else
  173.         x = LINKS;
  174.     rechts = 0;
  175.  
  176.     while(  x<v_weite  )
  177.     {
  178.         if(  x%8==0  )
  179.         {
  180.             UBYTE    *q=p+(x/8);
  181.  
  182.             i = 0;
  183.             while(  i<max_zeile  &&  *q==0  )
  184.             {
  185.                 i++;
  186.                 q += weite;
  187.             }
  188.             if(  i>=max_zeile  )
  189.             {
  190.                 WRITE( 5, "\33*b8Y" );
  191.                 x += 8;
  192.                 continue;
  193.             }
  194.             rechts = 0;
  195.             if(  i>7  )
  196.                 rechts = (i/8)-1;
  197.         }
  198.         drehe_90( p+rechts*8*weite, tmp2, weite, v_hoehe-rechts, x );
  199.  
  200.         /* Wir komprimieren */
  201.         for(  i=0, j=0;  i<v_hoehe-rechts  &&  j<v_hoehe-rechts;  /*Nichts*/  )
  202.         {
  203.             if(  find_next_same( &rep, tmp2+i, v_hoehe-i-rechts )  )
  204.             {
  205.                 /* Gleiche */
  206.                 druckzeile[j++] = 1-rep;
  207.                 druckzeile[j++] = tmp2[i];
  208.                 i += rep;
  209.             }
  210.             else
  211.             {
  212.                 /* Ungleiche */
  213.                 druckzeile[j++] = rep-1;
  214.                 while(  rep-->0  )
  215.                     druckzeile[j++] = tmp2[i++];
  216.             }
  217.         }
  218.  
  219.             /* Und nun den interessanten Rest */
  220.         if(  j<v_hoehe-rechts  )
  221.         {
  222.             /* Komprimieren brachte etwas */
  223.             strcpy( tmp1, "\33*b2m" );
  224.             ltoa( j, tmp1+5-modus, 10 );
  225.             strcat( tmp1, "W" );
  226.             WRITE( strlen(tmp1), tmp1 );
  227.             WRITE( j, druckzeile );
  228.             modus = 2;
  229.         }
  230.         else
  231.         {
  232.             /* Komprimieren brachte nichts */
  233.             j = v_hoehe-rechts;
  234.             strcpy( tmp1, "\33*b0m" );
  235.             ltoa( j, tmp1+3+modus, 10 );
  236.             strcat( tmp1, "W" );
  237.             WRITE( strlen(tmp1), tmp1 );
  238.             WRITE( j, tmp2 );
  239.             modus = 0;
  240.         }
  241.  
  242.         x++;    /* Nächste Zeile */
  243.     }
  244.  
  245.     /* Ende Grafikmodus */
  246.     /* Ende Seite */
  247.     if(  5!=WRITE( 5L, "\33*rB\14" )  )
  248.     {
  249.         /* Platz reichte nicht aus */
  250.         if(  th>0  )
  251.             Fclose( th );
  252.         th = -1;
  253.     }
  254.     if(  tmp_file[0]==0  )
  255.         flush_block();
  256.     return 0;
  257. }
  258. /* 22.1.93 */
  259.  
  260.  
  261.